Listing 10 - Page 0: No Title

##############################################################################
# Python From Scratch
# Autor: Nilo Ney Coutinho Menezes
# Editora Novatec (c) 2010-2024
# Site: https://pythonfromscratch.com
#
# File: listing\chapter 10\10.1452 - No Title.py
# Description: No Title
##############################################################################

from functools import total_ordering

@total_ordering
class Name:
    def __init__(self, name):
        if name is None or not name.strip():
            raise ValueError("Name cannot be null or blank")
        self.name = name
        self.key = Name.CreateKey(name)
    def __str__(self):
        return self.name
    def __repr__(self):
        return f"<Class {type(self).__name__} in 0x{id(self):x} Name: {self.name} Key: {self.key} >"
    def __eq__(self, other):
        print("__eq__ Called")
        return self.name == other.name
    def __lt__(self, other):
        print("__lt__ Called")
        return self.name < other.name
    @staticmethod
    def CreateKey(name):
        return name.strip().lower()
Click here to download the file